package com.siha_back.controller;

import com.siha_back.common.Result;
import com.siha_back.entity.dto.Major;
import com.siha_back.entity.dto.PageBean;
import com.siha_back.entity.dto.PushNotifications;
import com.siha_back.entity.dto.Resume;
import com.siha_back.service.PushNotificationsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("/pushNotifications")
public class PushNotificationsController {
    /**
     * 服务对象
     */
    @Autowired
    private PushNotificationsService pushNotificationsService;

//    /**
//     * 分页查询
//     *
//     * @param pushNotifications 筛选条件
//     * @param pageRequest      分页对象
//     * @return 查询结果
//     */
//    @GetMapping
//    public ResponseEntity<Page<PushNotifications>> queryByPage(PushNotifications pushNotifications, PageRequest pageRequest) {
//        return ResponseEntity.ok(this.pushNotificationsService.queryByPage(pushNotifications, pageRequest));
//    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/selectId")
    public ResponseEntity<PushNotifications> queryById(@RequestParam("id")Long id) {
        return ResponseEntity.ok(this.pushNotificationsService.queryById(id));
    }
//
//    /**
//     * 新增数据
//     *
//     * @param pushNotifications 实体
//     * @return 新增结果
//     */
//    @PostMapping
//    public ResponseEntity<PushNotifications> add(PushNotifications pushNotifications) {
//        return ResponseEntity.ok(this.pushNotificationsService.insert(pushNotifications));
//    }
//
//    /**
//     * 编辑数据
//     *
//     * @param pushNotifications 实体
//     * @return 编辑结果
//     */
//    @PutMapping
//    public ResponseEntity<PushNotifications> edit(PushNotifications pushNotifications) {
//        return ResponseEntity.ok(this.pushNotificationsService.update(pushNotifications));
//    }
//
//    /**
//     * 删除数据
//     *
//     * @param id 主键
//     * @return 删除是否成功
//     */
//    @DeleteMapping
//    public ResponseEntity<Boolean> deleteById(Long id) {
//        return ResponseEntity.ok(this.pushNotificationsService.deleteById(id));
//    }
    /**
     * 查询专业表(Major)
     *
     * @return 查询结果
     */
    /**
     * 查询专业表(Major)
     *
     * @return 查询结果
     */


    /**
     * 查询所有推送信息，通过majorId查询
     *
     * @return 查询是否成功
     */
    @GetMapping
    public Result<List<PushNotifications>> list(){
        ArrayList<PushNotifications> cs = (ArrayList<PushNotifications>) pushNotificationsService.list();
        if(cs == null){
            return Result.error("查询失败");
        }
        return Result.success(200,"成功",cs);
    }

    /**
     * 根据推送类型查询
     *
     * @return 查询是否成功
     */
    @GetMapping("/queryByNotificationId")
    public Result<List<PushNotifications>> queryByNotificationId(@RequestParam("notificationId")Integer notificationId){
        ArrayList<PushNotifications> cs = (ArrayList<PushNotifications>) pushNotificationsService.queryByNotificationId(notificationId);
        if(cs == null){
            return Result.error("查询失败");
        }
        return Result.success(200,"成功",cs);
    }

    /**
     * 查询所有推送信息并且分页
     *
     * @return 查询是否成功
     */
    @GetMapping("/list1")
    public Result<PageBean<PushNotifications>> list1(
            @RequestParam(value = "pageNum")Integer pageNum,
            @RequestParam(value = "pageSize")Integer pageSize,
            @RequestParam(value = "notificationId",required = false)Integer notificationId,
            @RequestParam(value = "title",required = false)String title){
        System.out.println(title);
        System.out.println(pageNum);
        System.out.println(pageSize);
        PageBean<PushNotifications> pb = pushNotificationsService.list1(pageNum,pageSize,notificationId,title);
        if (pb==null){
            return Result.error("查询失败");
        }
        System.out.println(pb);
        return Result.success(200,"成功",pb);
    }

}

